<script setup lang="ts">
import { ref } from 'vue';
import OrderList from './components/OrderList.vue';
import { ORDER_STATUS } from '@/constants/order';

const props = defineProps<{ type: string }>();

// tabs 数据
const orderTabs = [
  { type: 0, text: '全部' }, ...ORDER_STATUS.slice(0, 4)];

// 当前选中tab下标
const currentTabIndex = ref(orderTabs.findIndex(t => t.type === +props.type));
</script>

<template>
  <view class="viewport">
    <!-- tabs -->
    <view class="tabs">
      <text class="item" v-for="(item, index) in orderTabs" :key="item.type" @tap="currentTabIndex = index">
        {{ item.text }}
      </text>
      <!-- 游标 -->
      <view class="cursor" :style="{ left: currentTabIndex * 20 + '%' }"></view>
    </view>
    <!-- 滑动容器 -->
    <swiper class="swiper" :current="currentTabIndex" @change="({ detail }) => currentTabIndex = detail.current">
      <!-- 滑动项 -->
      <swiper-item v-for="item in orderTabs" :key="item.type">
        <!-- 订单列表 -->
        <OrderList :order-state="item.type" />
      </swiper-item>
    </swiper>
  </view>
</template>

<style lang="scss">
.viewport {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: #fff;
}

.tabs {
  display: flex;
  justify-content: space-around;
  line-height: 60rpx;
  margin: 0 10rpx;
  background-color: #fff;
  box-shadow: 0 4rpx 6rpx rgba(240, 240, 240, 0.6);
  position: relative;
  z-index: 9;

  .item {
    flex: 1;
    text-align: center;
    padding: 20rpx;
    font-size: 28rpx;
    color: #262626;
  }

  .cursor {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 20%;
    height: 6rpx;
    padding: 0 50rpx;
    background-color: #27ba9b;
    /* 过渡效果 */
    transition: all 0.4s;
  }
}

.swiper {
  background-color: #f7f7f8;
  flex: 1;
}
</style>